package com.qf.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.sys.po.Module;
import com.qf.sys.po.Role;
import com.qf.sys.service.ModuleService;
import com.qf.sys.util.LayUIOperate;
import com.qf.sys.util.Msg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @创建人 sunsir Email:sunsir163@163.com
 * @创建时间 2022/5/8
 * @描述
 */
@Controller
@RequestMapping("module")
public class ModuleController {
    @Resource
    ModuleService moduleService;

    @RequestMapping("getModuleList")
    @ResponseBody
    public Msg getModuleList(HttpServletRequest request){
        int pageSize =Integer.parseInt(request.getParameter("limit"));
        int pageNumber = Integer.parseInt(request.getParameter("page"));

        String mName = request.getParameter("mName");

        String _status = request.getParameter("status");
        System.out.println(_status);
        int status = 3;
        if (_status != null && !"".equals(_status)) {
            status = Integer.parseInt(_status);
        }
        Map params = new HashMap();
        params.put("mName", mName);
        params.put("status", status);
        System.out.println(status);
        PageHelper.startPage(pageNumber, pageSize);
        PageInfo<Module> data = moduleService.getModuleList(params);
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("处理成功");
        msg.setCount(data.getTotal());//得到总条数
        msg.setData(data.getList());//得到查出的List数据
        System.out.println(msg);
        return msg;
    }
    @RequestMapping("addModule")
    @ResponseBody
    public LayUIOperate addModule(@RequestBody Map<String,Object> params){
        LayUIOperate operate=new LayUIOperate();
        System.out.println("addModule -->"+params);
        boolean f= moduleService.addModule(params);
        if(f){
            operate.setSuccess(true);
            operate.setMessage("职位添加成功！牛逼");
        }else{
            operate.setSuccess(false);
            operate.setMessage("职位添加失败");
        }
        return operate;
    }
    @RequestMapping("updateModule")
    @ResponseBody
    public LayUIOperate updateModule(@RequestBody Map<String,Object> params){
        LayUIOperate operate=new LayUIOperate();
        System.out.println("updateModule -->"+params);
        boolean f= moduleService.updateModule(params);
        if(f){
            operate.setSuccess(true);
            operate.setMessage("职位修改成功！牛逼");
        }else{
            operate.setSuccess(false);
            operate.setMessage("职位修改失败");
        }
        return operate;
    }

    @RequestMapping("deleteModule")
    @ResponseBody
    public LayUIOperate deleteModule(Integer id){
        LayUIOperate operate=new LayUIOperate();
        boolean f= moduleService.deleteModule(id);
        if(f){
            operate.setSuccess(true);
            operate.setMessage("职位删除成功！");
        }else{
            operate.setSuccess(false);
            operate.setMessage("职位删除失败！");
        }
        return operate;
    }
    @RequestMapping("upadteModulestatusTo0")
    @ResponseBody
    public LayUIOperate upadteModulestatusTo0(int id){
        LayUIOperate operate=new LayUIOperate();
        boolean f= moduleService.upadteModulestatusTo0(id);
        if(f){
            operate.setSuccess(true);
            operate.setMessage("用户删除成功！牛逼");
        }else{
            operate.setSuccess(false);
            operate.setMessage("用户删除失败");
        }
        return operate;
    }
    @RequestMapping("upadteModulestatusTo1")
    @ResponseBody
    public LayUIOperate upadteModulestatusTo1(int id){
        LayUIOperate operate=new LayUIOperate();
        boolean f= moduleService.upadteModulestatusTo1(id);
        if(f){
            operate.setSuccess(true);
            operate.setMessage("用户删除成功！牛逼");
        }else{
            operate.setSuccess(false);
            operate.setMessage("用户删除失败");
        }
        return operate;
    }

    @RequestMapping("getModuleByLevel1")
    @ResponseBody
    public Msg getModuleByLevel1(){

        List<Module> data= moduleService.getModuleByLevel1();
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("处理成功");
        msg.setCount(100);//得到总条数
        msg.setData(data);//得到查出的List数据
        System.out.println(msg);
        return msg;
    }
    @RequestMapping("getModuleByLevel2")
    @ResponseBody
    public Msg getModuleByLevel2(){
        List<Module> data= moduleService.getModuleByLevel2();
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("处理成功");
        msg.setCount(100);//得到总条数
        msg.setData(data);//得到查出的List数据
        System.out.println(msg);
        return msg;
    }



}
